package com.geekcoding.geekoj.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.geekcoding.geekoj.entity.TestAnswer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface TestAnswerMapper extends BaseMapper<TestAnswer> {
    @Select("select a.answer_id, a.num, b.`name`, b.nick_name FROM (select answer_id, count(1) as num from geekoj_test_answer group by answer_id order by num desc limit 5) a left JOIN geekoj_user b ON a.answer_id = b.id")
    List<Map<String, Object>> rankingByCount();

    @Select("select a.answer_id, a.num, b.`name`, b.nick_name FROM (select answer_id, count(1) as num from geekoj_test_answer where correct_result = 'YES' group by answer_id order by num desc limit 5) a left JOIN geekoj_user b ON a.answer_id = b.id")
    List<Map<String, Object>> rankingByYes();

    @Select("select a.answer_id, a.num, b.`name`, b.nick_name FROM (select answer_id, count(1) as num from geekoj_test_answer where correct_result = 'NO' group by answer_id order by num desc limit 5) a left JOIN geekoj_user b ON a.answer_id = b.id")
    List<Map<String, Object>> rankingByNo();
}
